﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using HYFamilyLibDataManager;

namespace HYRElectric.Calculate
{
	public partial class DlgDatabaseManager : System.Windows.Forms.Form
	{
		public DlgDatabaseManager(SqliteElectricDatabase db)
		{
			this.m_db = db;
			this.InitializeComponent();
			this.InitCbxLampType();
			this.InitClbLampType();
			this.dataGridView1.Controls.Add(this.comboBox1);
			this.dataGridView2.Controls.Add(this.comboBox2);
			this.dataGridView2.Controls.Add(this.comboBox4);
			this.dataGridView2.Controls.Add(this.checkedListBox1);
			this.dataGridView1.CellEnter += this.dataGridView1_CellEnter;
			this.dataGridView1.CellLeave += this.dataGridView1_CellLeave;
			this.dataGridView1.DataError += this.dataGridView1_DataError;
			this.dataGridView3.DataError += this.dataGridView3_DataError;
			this.getLampType();
		}

		private void dataGridView3_DataError(object sender, DataGridViewDataErrorEventArgs e)
		{
			MessageBox.Show("输入的数据格式不正确！");
		}

		private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
		{
			MessageBox.Show("输入的数据格式不正确！");
		}

		private void getLampType()
		{
			this.cbxSelectByType.Items.Clear();
			DataTable allLampType = this.m_db.GetAllLampType();
			for (int i = 0; i < allLampType.Rows.Count; i++)
			{
				this.cbxSelectByType.Items.Add(allLampType.Rows[i][0]);
			}
			this.cbxSelectByType.SelectedIndex = 0;
		}

		private void rdbType_CheckedChanged(object sender, EventArgs e)
		{
			this.getLampType();
			this.cbxSelectByType.Enabled = this.rdbType.Checked;
			this.cbxSelectByFactory.Enabled = this.rdbFactory.Checked;
		}

		private void rdbFactory_CheckedChanged(object sender, EventArgs e)
		{
			this.getLampFactory();
			this.cbxSelectByType.Enabled = this.rdbType.Checked;
			this.cbxSelectByFactory.Enabled = this.rdbFactory.Checked;
		}

		private void cbxSelectByType_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cbxSelectByType.SelectedItem != null)
			{
				this.dataGridView1.DataSource = this.m_db.ExecQuery(string.Format("select b.[ID],a.[LampType] as 光源类别, b.[LampStyle] as 光源型号,b.[LuminousFlux] as 光通量,b.[LampPower] as 功率,b.[LampFactory] as 厂家,b.[LampName] as 名称 from [Illuminant] as b inner join [LampType] as a on a.[ID]=b.[LampTypeID] where a.[LampType]='{0}'", this.cbxSelectByType.SelectedItem.ToString()));
				this.dataGridView1.Columns["ID"].Visible = false;
			}
		}

		private void setCbxWidth(ComboBox cbx)
		{
			int num = 0;
			Graphics graphics = base.CreateGraphics();
			for (int i = 0; i < cbx.Items.Count; i++)
			{
				cbx.SelectedIndex = i;
				SizeF sizeF = graphics.MeasureString(cbx.Text, cbx.Font);
				if (num < (int)sizeF.Width)
				{
					num = (int)sizeF.Width;
				}
			}
			cbx.DropDownWidth = cbx.Width;
			if (cbx.DropDownWidth < num)
			{
				cbx.DropDownWidth = num;
			}
		}

		private void InitCbxLampType()
		{
			this.comboBox1.Items.Clear();
			DataTable allLampType = this.m_db.GetAllLampType();
			for (int i = 0; i < allLampType.Rows.Count; i++)
			{
				this.comboBox1.Items.Add(allLampType.Rows[i][0]);
			}
			this.comboBox1.SelectedIndex = 0;
			this.setCbxWidth(this.comboBox1);
		}

		private void InitClbLampType()
		{
			this.checkedListBox1.Items.Clear();
			DataTable allLampType = this.m_db.GetAllLampType();
			for (int i = 0; i < allLampType.Rows.Count; i++)
			{
				this.checkedListBox1.Items.Add(allLampType.Rows[i][0]);
			}
			this.checkedListBox1.SelectedIndex = 0;
		}

		private void InitCbxDefSrc(string lampTypeNames)
		{
			string[] array = lampTypeNames.Split(new char[]
			{
				','
			});
			this.comboBox2.Items.Clear();
			foreach (string name in array)
			{
				List<string> defaultLightSrcs = this.getDefaultLightSrcs(this.getLampId(name));
				for (int j = 0; j < defaultLightSrcs.Count; j++)
				{
					this.comboBox2.Items.Add(defaultLightSrcs[j]);
				}
			}
			if (this.comboBox2.Items.Count > 0)
			{
				this.comboBox2.SelectedIndex = 0;
				this.setCbxWidth(this.comboBox2);
			}
		}

		private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex == this.comboBoxColumnIndex)
			{
				DataGridViewCell dataGridViewCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
				Rectangle cellDisplayRectangle = this.dataGridView1.GetCellDisplayRectangle(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex, true);
				this.comboBox1.Location = cellDisplayRectangle.Location;
				this.comboBox1.Size = cellDisplayRectangle.Size;
				this.comfirmComboBoxValue(this.comboBox1, dataGridViewCell.Value as string);
				this.comboBox1.Visible = true;
			}
		}

		private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex == this.comboBoxColumnIndex)
			{
				DataGridViewCell dataGridViewCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
				if (this.comboBox1.Text != "")
				{
					dataGridViewCell.Value = this.comboBox1.Text;
				}
				this.comboBox1.Visible = false;
			}
		}

		private void comfirmComboBoxValue(ComboBox com, string cellValue)
		{
			com.SelectedIndex = -1;
			if (cellValue == null)
			{
				com.Text = "";
				return;
			}
			com.Text = cellValue;
			foreach (object obj in com.Items)
			{
				if ((string)obj == cellValue)
				{
					com.SelectedItem = obj;
				}
			}
		}

		private void comfirmClbValue(CheckedListBox clb, string cellValue)
		{
			foreach (object obj in clb.CheckedIndices)
			{
				int index = (int)obj;
				clb.SetItemChecked(index, false);
			}
			if (cellValue == null)
			{
				return;
			}
			foreach (string value in cellValue.Split(new char[]
			{
				','
			}))
			{
				if (clb.Items.Contains(value))
				{
					clb.SetItemChecked(clb.Items.IndexOf(value), true);
				}
			}
		}

		private void cbxSelectByFactory_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cbxSelectByFactory.SelectedItem != null)
			{
				this.dataGridView1.DataSource = this.m_db.ExecQuery(string.Format("select b.[ID],a.[LampType] as 光源类别, b.[LampStyle] as 光源型号,b.[LuminousFlux] as 光通量,b.[LampPower] as 功率,b.[LampFactory] as 厂家,b.[LampName] as 名称 from [Illuminant] as b inner join [LampType] as a on a.[ID]=b.[LampTypeID] where b.[LampFactory]='{0}'", this.cbxSelectByFactory.SelectedItem.ToString()));
			}
			this.dataGridView1.Columns["ID"].Visible = false;
		}

		private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.comboBox3.SelectedItem != null)
			{
				this.gerLamp();
			}
		}

		private void gerLamp()
		{
			this.dataGridView2.Rows.Clear();
			DataTable dataTable = this.m_db.ExecQuery(string.Format("select [id] from [LampType] where [LampType]='{0}'", this.comboBox3.SelectedItem.ToString()));
			if (dataTable.Rows.Count > 0)
			{
				string value = dataTable.Rows[0][0].ToString();
				DataTable dataTable2 = this.m_db.ExecQuery(string.Format("select [ID],[LampName],[LampStyle],[LampEfficiency],[MaxJGBAA],[MaxJGBBB],[LampTypeID],[DefaultLightSrc],[LightSrcCount],[BallastCount],[BallastPower],[LampFactory],[UtilizationFactorType] from [Lamp]", Array.Empty<object>()));
				if (dataTable2.Rows.Count > 0)
				{
					for (int i = 0; i < dataTable2.Rows.Count; i++)
					{
						string[] array = dataTable2.Rows[i][6].ToString().Trim().Split(new char[]
						{
							','
						});
						string lampTypes = this.getLampTypes(array);
						string text;
						if (dataTable2.Rows[i][12].ToString().Trim() == "0")
						{
							text = "RCR";
						}
						else
						{
							text = "RI";
						}
						string defaultLightSrc = this.getDefaultLightSrc(Convert.ToInt32(dataTable2.Rows[i][7]));
						if (array.Contains(value))
						{
							this.dataGridView2.Rows.Add(new object[]
							{
								dataTable2.Rows[i][0].ToString(),
								dataTable2.Rows[i][1].ToString(),
								dataTable2.Rows[i][2].ToString(),
								dataTable2.Rows[i][3].ToString(),
								dataTable2.Rows[i][4].ToString(),
								dataTable2.Rows[i][5].ToString(),
								lampTypes,
								defaultLightSrc,
								dataTable2.Rows[i][8].ToString(),
								dataTable2.Rows[i][9].ToString(),
								dataTable2.Rows[i][10].ToString(),
								dataTable2.Rows[i][11].ToString(),
								text
							});
						}
					}
				}
			}
		}

		private string getDefaultLightSrc(int id)
		{
			string result = "";
			DataTable dataTable = this.m_db.ExecQuery(string.Format("select [LampName],[LampStyle] from [Illuminant] where [id]='{0}'", id));
			if (dataTable.Rows.Count > 0)
			{
				result = dataTable.Rows[0][0].ToString().Trim() + ":" + dataTable.Rows[0][1].ToString().Trim();
			}
			return result;
		}

		private List<string> getDefaultLightSrcs(int lampTypeIDId)
		{
			List<string> list = new List<string>();
			DataTable dataTable = this.m_db.ExecQuery(string.Format("select [LampName],[LampStyle] from [Illuminant] where [LampTypeID]='{0}'", lampTypeIDId));
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				list.Add(dataTable.Rows[i][0].ToString().Trim() + ":" + dataTable.Rows[i][1].ToString().Trim());
			}
			return list;
		}

		private string getLampTypes(string[] typeIds)
		{
			string text = this.m_db.ExecQuery(string.Format("select [LampType] from [LampType] where [id]='{0}'", typeIds[0])).Rows[0][0].ToString();
			if (typeIds.Count<string>() > 1)
			{
				for (int i = 1; i < typeIds.Count<string>(); i++)
				{
					text = text + "," + this.m_db.ExecQuery(string.Format("select [LampType] from [LampType] where [id]='{0}'", typeIds[i])).Rows[0][0].ToString();
				}
			}
			return text;
		}

		private int getLampTypeId(string typeName)
		{
			return Convert.ToInt32(this.m_db.ExecQuery(string.Format("select [ID] from [LampType] where [LampType]='{0}'", typeName)).Rows[0][0]);
		}

		private string getLampTypeIds(string typeNames)
		{
			string[] array = typeNames.Split(new char[]
			{
				','
			});
			List<string> list = new List<string>();
			for (int i = 0; i < array.Count<string>(); i++)
			{
				list.Add(this.getLampTypeId(array[i]).ToString().Trim());
			}
			return string.Join(",", list);
		}

		private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
		{
			if (this.treeView1.SelectedNode != null)
			{
				this.dataGridView3.DataSource = this.m_db.ExecQuery(string.Format("select [ID],[Place] as 场所,[ReferencePlane] as 参考平面,[PowerDensityNowV] as 现行功率密度,[PowerDensityObjV] as 目标功率密度,[IlluminanceStandard] as 照度标准值,[GlareValue] as 统一标准值,[Ra] as 显色指数 from [IllAndPower] where [BuildingType]='{0}'", this.treeView1.SelectedNode.Text.Trim()));
				this.dataGridView3.Columns["ID"].Visible = false;
			}
		}

		private void tabControl1_Selected(object sender, TabControlEventArgs e)
		{
			if (this.tabControl1.SelectedTab == this.tabPage1)
			{
				this.getLampFactory();
				this.getLampType();
				return;
			}
			if (this.tabControl1.SelectedTab == this.tabPage2)
			{
				this.comboBox3.Items.Clear();
				DataTable allLampType = this.m_db.GetAllLampType();
				for (int i = 0; i < allLampType.Rows.Count; i++)
				{
					this.comboBox3.Items.Add(allLampType.Rows[i][0]);
				}
				this.comboBox3.SelectedIndex = 0;
				return;
			}
			if (this.tabControl1.SelectedTab == this.tabPage3)
			{
				this.m_db.FillIllAndPowerTree(this.treeView1);
				this.treeView1.ExpandAll();
				this.dataGridView3.DataSource = null;
			}
		}

		private void getLampFactory()
		{
			this.cbxSelectByFactory.Items.Clear();
			DataTable allFactory = this.m_db.GetAllFactory();
			for (int i = 0; i < allFactory.Rows.Count; i++)
			{
				this.cbxSelectByFactory.Items.Add(allFactory.Rows[i][0]);
			}
			this.cbxSelectByFactory.SelectedIndex = 0;
		}

		private int getLampId(string name)
		{
			DataTable dataTable = this.m_db.ExecQuery(string.Format("select [ID] from [LampType] where [LampType]='{0}'", name));
			if (dataTable != null && dataTable.Rows.Count > 0)
			{
				return Convert.ToInt32(dataTable.Rows[0][0]);
			}
			return -1;
		}

		private int getLightSrcId(string strSrc)
		{
			if (!(strSrc != ""))
			{
				return -1;
			}
			string[] array = strSrc.Split(new char[]
			{
				':'
			});
			DataTable dataTable = this.m_db.ExecQuery(string.Format("select [ID] from [Illuminant] where [LampStyle]='{0}' and [LampName]='{1}'", array[1].Trim(), array[0].Trim()));
			if (dataTable.Rows.Count > 0)
			{
				return Convert.ToInt32(dataTable.Rows[0][0]);
			}
			return -1;
		}

		private void dataGridView2_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			DataGridViewCell dataGridViewCell = this.dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];
			Rectangle cellDisplayRectangle = this.dataGridView2.GetCellDisplayRectangle(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex, false);
			if (e.ColumnIndex == 7)
			{
				string lampTypeNames = this.dataGridView2.Rows[e.RowIndex].Cells[6].Value.ToString();
				this.InitCbxDefSrc(lampTypeNames);
				this.comboBox2.Location = cellDisplayRectangle.Location;
				this.comboBox2.Size = cellDisplayRectangle.Size;
				this.comfirmComboBoxValue(this.comboBox2, dataGridViewCell.Value as string);
				this.comboBox2.Visible = true;
				return;
			}
			if (e.ColumnIndex == 6)
			{
				this.checkedListBox1.Location = cellDisplayRectangle.Location;
				this.checkedListBox1.Width = cellDisplayRectangle.Width;
				this.comfirmClbValue(this.checkedListBox1, dataGridViewCell.Value as string);
				this.checkedListBox1.Visible = true;
				return;
			}
			if (e.ColumnIndex == 12)
			{
				this.comboBox4.Location = cellDisplayRectangle.Location;
				this.comboBox4.Size = cellDisplayRectangle.Size;
				this.comboBox4.Visible = true;
			}
		}

		private void dataGridView2_CellLeave(object sender, DataGridViewCellEventArgs e)
		{
			DataGridViewCell dataGridViewCell = this.dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];
			if (e.ColumnIndex == 7)
			{
				dataGridViewCell.Value = this.comboBox2.Text;
				this.comboBox2.Visible = false;
				return;
			}
			if (e.ColumnIndex == 6)
			{
				string text = "";
				List<string> list = new List<string>();
				foreach (object obj in this.checkedListBox1.CheckedIndices)
				{
					int index = (int)obj;
					if (this.checkedListBox1.GetItemChecked(index))
					{
						list.Add(this.checkedListBox1.Items[index].ToString());
					}
				}
				if (list.Count >= 1)
				{
					text = list[0];
					for (int i = 1; i < list.Count; i++)
					{
						text = text + "," + list[i];
					}
				}
				else if (list.Count == 1)
				{
					text = list[0];
				}
				dataGridViewCell.Value = text;
				this.checkedListBox1.Visible = false;
				return;
			}
			if (e.ColumnIndex == 12)
			{
				dataGridViewCell.Value = this.comboBox4.Text;
				this.comboBox4.Visible = false;
			}
		}

		private int getUtilizationFactorTypeId(string FactorType)
		{
            int result = -1;
			if (FactorType.Trim().Equals("RCR"))
			{
				result = 0;
			}
			else if (FactorType.Trim().Equals("RI"))
			{
				result = 1;
			}
			return result;
		}

		private void button1_Click(object sender, EventArgs e)
		{
			if (this.tabControl1.SelectedTab == this.tabPage1 && this.dataGridView1.Rows.Count > 1)
			{
				try
				{
					DataTable dataTable = (DataTable)this.dataGridView1.DataSource;
					for (int i = 0; i < dataTable.Rows.Count; i++)
					{
						int lampTypeId = this.getLampTypeId(dataTable.Rows[i]["光源类别"].ToString());
						if (this.dataGridView1.Rows[i].Cells["ID"].Value != null && dataTable.Rows[i]["ID"].ToString() != "")
						{
							this.m_db.ExecuteCommand(string.Format("update [Illuminant] set [LampTypeID]='{0}',[LampStyle]='{1}',[LuminousFlux]='{2}',[LampPower]='{3}',[LampFactory]='{4}',[LampName]='{5}' where [ID]='{6}'", new object[]
							{
								lampTypeId,
								dataTable.Rows[i]["光源型号"].ToString(),
								dataTable.Rows[i]["光通量"].ToString(),
								dataTable.Rows[i]["功率"].ToString(),
								dataTable.Rows[i]["厂家"].ToString(),
								dataTable.Rows[i]["名称"].ToString(),
								dataTable.Rows[i]["ID"].ToString()
							}));
						}
						else
						{
							this.m_db.ExecuteCommand(string.Format("insert into [Illuminant] ([LampTypeID],[LampStyle],[LuminousFlux],[LampPower],[LampFactory],[LampName]) values('{0}','{1}','{2}','{3}','{4}','{5}')", new object[]
							{
								lampTypeId,
								dataTable.Rows[i]["光源型号"].ToString(),
								dataTable.Rows[i]["光通量"].ToString(),
								dataTable.Rows[i]["功率"].ToString(),
								dataTable.Rows[i]["厂家"].ToString(),
								dataTable.Rows[i]["名称"].ToString()
							}));
						}
					}
					MessageBox.Show("提交成功！");
					return;
				}
				catch (Exception)
				{
					MessageBox.Show("提交发生异常！请检查录入的数据是否有重复。");
					return;
				}
			}
			if (this.tabControl1.SelectedTab == this.tabPage2 && this.dataGridView2.Rows.Count > 1)
			{
				try
				{
					for (int j = 0; j < this.dataGridView2.Rows.Count - 1; j++)
					{
						if (this.dataGridView2.Rows[j].Cells["LampTypeID"] != null)
						{
							string lampTypeIds = this.getLampTypeIds(this.dataGridView2.Rows[j].Cells["LampTypeID"].Value.ToString());
							int num = (this.dataGridView2.Rows[j].Cells["DefaultLightSrc"].Value == null) ? -1 : this.getLightSrcId(this.dataGridView2.Rows[j].Cells["DefaultLightSrc"].Value.ToString().Trim());
							int num2 = (this.dataGridView2.Rows[j].Cells["UtilizationFactorType"].Value == null) ? 0 : this.getUtilizationFactorTypeId(this.dataGridView2.Rows[j].Cells["UtilizationFactorType"].Value.ToString());
							string text = (this.dataGridView2.Rows[j].Cells["LampFactory"].Value == null) ? "" : this.dataGridView2.Rows[j].Cells["LampFactory"].Value.ToString();
							string text2 = (this.dataGridView2.Rows[j].Cells["LampName"].Value == null) ? "" : this.dataGridView2.Rows[j].Cells["LampName"].Value.ToString();
							string text3 = (this.dataGridView2.Rows[j].Cells["LampStyle"].Value == null) ? "" : this.dataGridView2.Rows[j].Cells["LampStyle"].Value.ToString();
							string text4 = (this.dataGridView2.Rows[j].Cells["LampEfficiency"].Value == null) ? "0" : this.dataGridView2.Rows[j].Cells["LampEfficiency"].Value.ToString();
							string text5 = (this.dataGridView2.Rows[j].Cells["MaxJGBAA"].Value == null) ? "0" : this.dataGridView2.Rows[j].Cells["MaxJGBAA"].Value.ToString();
							string text6 = (this.dataGridView2.Rows[j].Cells["MaxJGBBB"].Value == null) ? "0" : this.dataGridView2.Rows[j].Cells["MaxJGBBB"].Value.ToString();
							string text7 = (this.dataGridView2.Rows[j].Cells["LightSrcCount"].Value == null) ? "0" : this.dataGridView2.Rows[j].Cells["LightSrcCount"].Value.ToString();
							string text8 = (this.dataGridView2.Rows[j].Cells["BallastCount"].Value == null) ? "0" : this.dataGridView2.Rows[j].Cells["BallastCount"].Value.ToString();
							string text9 = (this.dataGridView2.Rows[j].Cells["BallastPower"].Value == null) ? "0" : this.dataGridView2.Rows[j].Cells["BallastPower"].Value.ToString();
							if (this.dataGridView2.Rows[j].Cells["ID"].Value != null && this.dataGridView2.Rows[j].Cells["ID"].Value.ToString() != "")
							{
								this.m_db.ExecuteCommand(string.Format("update [Lamp] set [LampName]='{0}',[LampStyle]='{1}',[LampEfficiency]='{2}',[MaxJGBAA]='{3}',[MaxJGBBB]='{4}',[LampTypeID]='{5}',[DefaultLightSrc]='{6}',[LightSrcCount]='{7}',[BallastCount]='{8}',[BallastPower]='{9}',[LampFactory]='{10}',[UtilizationFactorType]='{11}' where [ID]='{12}'", new object[]
								{
									text2,
									text3,
									text4,
									text5,
									text6,
									lampTypeIds,
									num,
									text7,
									text8,
									text9,
									text,
									num2.ToString(),
									this.dataGridView2.Rows[j].Cells["ID"].Value.ToString()
								}));
							}
							else
							{
								this.m_db.ExecuteCommand(string.Format("insert into [Lamp] ([LampName],[LampStyle],[LampEfficiency],[MaxJGBAA],[MaxJGBBB],[LampTypeID],[DefaultLightSrc],[LightSrcCount],[BallastCount],[BallastPower],[LampFactory],[UtilizationFactorType]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", new object[]
								{
									text2,
									text3,
									text4,
									text5,
									text6,
									lampTypeIds,
									num,
									text7,
									text8,
									text9,
									text,
									num2.ToString()
								}));
							}
						}
					}
					this.gerLamp();
					MessageBox.Show("提交成功！");
					return;
				}
				catch (Exception)
				{
					MessageBox.Show("提交发生异常！请检查灯具类别是否为空或录入的数据是否有重复。");
					return;
				}
			}
			if (this.tabControl1.SelectedTab == this.tabPage3 && this.dataGridView3.Rows.Count > 1)
			{
				try
				{
					for (int k = 0; k < this.dataGridView3.Rows.Count - 1; k++)
					{
						string text10 = this.treeView1.SelectedNode.Text;
						string text11 = this.treeView1.SelectedNode.Parent.Text;
						if (this.dataGridView3.Rows[k].Cells["ID"].Value != null && this.dataGridView3.Rows[k].Cells["ID"].Value.ToString() != "")
						{
							this.m_db.ExecuteCommand(string.Format("update [IllAndPower] set [Place]='{0}',[ReferencePlane]='{1}',[PowerDensityNowV]='{2}',[PowerDensityObjV]='{3}',[IlluminanceStandard]='{4}',[GlareValue]='{5}',[Ra]='{6}' where [ID]='{7}'", new object[]
							{
								this.dataGridView3.Rows[k].Cells["场所"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["参考平面"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["现行功率密度"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["目标功率密度"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["照度标准值"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["统一标准值"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["显色指数"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["ID"].Value.ToString()
							}));
						}
						else
						{
							this.m_db.ExecuteCommand(string.Format("insert into [IllAndPower] ([Trade],[BuildingType],[Place],[ReferencePlane],[PowerDensityNowV],[PowerDensityObjV],[IlluminanceStandard],[GlareValue],[Ra]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", new object[]
							{
								text11,
								text10,
								this.dataGridView3.Rows[k].Cells["场所"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["参考平面"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["现行功率密度"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["目标功率密度"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["照度标准值"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["统一标准值"].Value.ToString(),
								this.dataGridView3.Rows[k].Cells["显色指数"].Value.ToString()
							}));
						}
					}
					MessageBox.Show("提交成功！");
				}
				catch (Exception)
				{
					MessageBox.Show("提交发生异常！请检查录入的数据是否有重复。");
				}
			}
		}

		private void button2_Click(object sender, EventArgs e)
		{
			try
			{
				if (this.tabControl1.SelectedTab == this.tabPage1)
				{
					if (this.dataGridView1.SelectedRows[0].Index == this.dataGridView1.Rows.Count - 1 || DialogResult.Yes != MessageBox.Show("是否要将选中项删除？", "照度计算数据库管理器", MessageBoxButtons.YesNo))
					{
						goto IL_3B2;
					}
					IEnumerator enumerator = this.dataGridView1.SelectedRows.GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							object obj = enumerator.Current;
							DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
							if (dataGridViewRow.Cells["ID"].Value != null && dataGridViewRow.Cells["ID"].Value.ToString() != "")
							{
								this.m_db.ExecuteCommand(string.Format("delete from [Illuminant] where [ID]='{0}'", dataGridViewRow.Cells["ID"].Value.ToString()));
								this.dataGridView1.Rows.Remove(dataGridViewRow);
							}
							else
							{
								this.dataGridView1.Rows.Remove(dataGridViewRow);
							}
						}
						goto IL_3B2;
					}
				}
				if (this.tabControl1.SelectedTab == this.tabPage2)
				{
					if (this.dataGridView2.SelectedRows[0].Index == this.dataGridView2.Rows.Count - 1 || DialogResult.Yes != MessageBox.Show("是否要将选中项删除？", "照度计算数据库管理器", MessageBoxButtons.YesNo))
					{
						goto IL_3B2;
					}
					IEnumerator enumerator = this.dataGridView2.SelectedRows.GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							object obj2 = enumerator.Current;
							DataGridViewRow dataGridViewRow2 = (DataGridViewRow)obj2;
							if (dataGridViewRow2.Cells["ID"].Value != null && dataGridViewRow2.Cells["ID"].Value.ToString() != "")
							{
								this.m_db.ExecuteCommand(string.Format("delete from [Lamp] where [ID]='{0}'", dataGridViewRow2.Cells["ID"].Value.ToString()));
								this.dataGridView2.Rows.Remove(dataGridViewRow2);
							}
							else
							{
								this.dataGridView2.Rows.Remove(dataGridViewRow2);
							}
						}
						goto IL_3B2;
					}
				}
				if (this.tabControl1.SelectedTab == this.tabPage3)
				{
					if (this.dataGridView3.SelectedRows.Count <= 0)
					{
						MessageBox.Show("请选择要删除的“照度要求及功率密度”参数行！", "盈建科提示");
					}
					else if (this.dataGridView3.SelectedRows[0].Index != this.dataGridView3.Rows.Count - 1 && DialogResult.Yes == MessageBox.Show("是否要将选中项删除？", "照度计算数据库管理器", MessageBoxButtons.YesNo))
					{
						foreach (object obj3 in this.dataGridView3.SelectedRows)
						{
							DataGridViewRow dataGridViewRow3 = (DataGridViewRow)obj3;
							if (dataGridViewRow3.Cells["ID"].Value != null && dataGridViewRow3.Cells["ID"].Value.ToString() != "")
							{
								this.m_db.ExecuteCommand(string.Format("delete from [IllAndPower] where [ID]='{0}'", dataGridViewRow3.Cells["ID"].Value.ToString()));
								this.dataGridView3.Rows.Remove(dataGridViewRow3);
							}
							else
							{
								this.dataGridView3.Rows.Remove(dataGridViewRow3);
							}
						}
					}
				}
				IL_3B2:;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void button3_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void button4_Click(object sender, EventArgs e)
		{
		}

		private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex == 13)
			{
				if (this.dataGridView2.Rows[e.RowIndex].Cells["ID"].Value != null)
				{
					using (DlgLYXS dlgLYXS = new DlgLYXS(this.m_db, Convert.ToInt32(this.dataGridView2.Rows[e.RowIndex].Cells["ID"].Value)))
					{
						dlgLYXS.ShowDialog();
						return;
					}
				}
				MessageBox.Show("请先将灯具提交再维护利用系数表！");
			}
		}

		private void DlgDatabaseManager_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
		{
		}

		private void treeView1_Leave(object sender, EventArgs e)
		{
			if (this.treeView1.SelectedNode != null)
			{
				this.treeView1.SelectedNode.BackColor = Color.Gray;
			}
		}

		private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
		{
			if (this.treeView1.SelectedNode != null)
			{
				this.treeView1.SelectedNode.BackColor = Color.Empty;
			}
		}

		private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private SqliteElectricDatabase m_db;

		private int comboBoxColumnIndex = 1;
	}
}
